/// @tags: DPonTreewithCircle
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

namespace BlueQuantum {

int const N = 1e5 + 5;

int e_cnt, n, m, rt, tim, vis[N], fa[N], deg[N], heads[N];
double f[N], sum[N], tmp[N], g[N], ans;
bool cir[N];

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void getF(int x) {
  vis[x] = true;
  for (int i = heads[x], v; i; i = e[i].nxt)
    if (!vis[v = e[i].v] && !cir[v]) getF(v), deg[x]++, sum[x] += f[v] + e[i].w;
  if (deg[x]) f[x] = sum[x] / deg[x];
  if (x != rt) deg[x]++;
}

void getG(int x) {
  vis[x] = true;
  for (int i = heads[x], v; i; i = e[i].nxt)
    if (!vis[v = e[i].v] && !cir[v])
      sum[v] += (sum[x] - f[v] - e[i].w) / max(1, deg[x] - 1) + e[i].w, getG(v);
}

void getCircle(int x) {
  vis[x] = ++tim;
  for (int i = heads[x], j, v; i; i = e[i].nxt)
    if ((v = e[i].v) != fa[x]) {
      if (!vis[v]) fa[v] = x, getCircle(v);
      else if (vis[v] < vis[x])
        for (cir[v] = true, j = x; j != v; j = fa[j]) cir[j] = true;
    }
}

void solve(int x, int fa) {
  bool flag = false;
  g[x] = 0;
  for (int i = heads[x], v; i; i = e[i].nxt)
    if ((v = e[i].v) != rt && v != fa && cir[v])
      flag = true, solve(v, x), g[x] += g[v] + e[i].w;
  if (x == rt) return;
  int d = deg[x];
  if (!d) ++d;
  if (!flag) g[x] = sum[x] / (double)d;
  else
    d = deg[x] + 1, g[x] = (g[x] + sum[x]) / (double)d;
}

inline int main() {
  cin >> n >> m;
  for (int i = 1, u, v, w; i <= m; ++i) cin >> u >> v >> w, add(u, v, w), add(v, u, w);
  if (m == n - 1) rt = 1, getF(1), memset(vis, 0, sizeof(vis)), getG(1);
  else {
    getCircle(1);
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; ++i)
      if (cir[i]) rt = i, getF(i);
    for (int i = 1; i <= n; ++i)
      if (cir[i]) rt = i, solve(i, 0), tmp[i] = g[i];
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; ++i)
      if (cir[i]) deg[i] += 2, sum[i] += tmp[i];
    for (int i = 1; i <= n; ++i)
      if (cir[i]) rt = i, getG(i);
  }
  for (int i = 1; i <= n; ++i) ans += sum[i] / deg[i];
  cout << ans / n;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P2081 [NOI2012] 迷失游乐园.in", "r", stdin);
  freopen("P2081 [NOI2012] 迷失游乐园.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
